package com.bignerdranch.android.ecar.Adapter;

import android.content.Context;
import android.support.design.widget.Snackbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bignerdranch.android.ecar.Bean.RefuelBean;
import com.bignerdranch.android.ecar.R;

import java.util.List;


/**
 * Created by Administrator on 2016/7/25.
 */
public class RefuelAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<RefuelBean> mData;

    public RefuelAdapter(Context context, List<RefuelBean> data) {
        mContext = context;
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.refuel_item, null);
        }
        ViewHold hold = new ViewHold();
        if (convertView.getTag() == null) {
            hold.name = (TextView) convertView.findViewById(R.id.name);
            hold.distance = (TextView) convertView.findViewById(R.id.distance);
            hold.location = (TextView) convertView.findViewById(R.id.location);
            hold.map = (LinearLayout) convertView.findViewById(R.id.map);
            hold.phone = (LinearLayout)convertView.findViewById(R.id.phone);
            convertView.setTag(hold);
        } else {
            hold = (ViewHold) convertView.getTag();
        }

        hold.name.setText(mData.get(position).getName());
        hold.distance.setText(mData.get(position).getDistance());
        hold.location.setText(mData.get(position).getLocation());
        hold.map.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        hold.phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v,"客服热线",Snackbar.LENGTH_SHORT).show();
            }
        });

        return convertView;
    }

    private static class ViewHold {
        private TextView name;
        private TextView distance;
        private TextView location;
        private LinearLayout map;
        private LinearLayout phone;

    }
}
